package com.blog.rabbitmqdemo;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author DongZH
 * @since 2025/6/5 - 21:58
 **/
public class ConnectionUtil {
    public static final String HOST_ADDRESS = "117.72.76.16";
    public static Connection getConnection() throws Exception {
        // 定义连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        // 设置主机地址
        connectionFactory.setHost(HOST_ADDRESS);
        // 设置连接端口号：默认为5672
        connectionFactory.setPort(5672);
        // 虚拟主机名称：默认为 /
        connectionFactory.setVirtualHost("/");
        // 设置连接用户名：默认为guest
        connectionFactory.setUsername("guest");
        // 设置连接密码，默认为123456
        connectionFactory.setPassword("123456");
        // 创建连接
        Connection connection = connectionFactory.newConnection();
        return connection;
    }

    public static void main(String[] args) throws Exception {
        Connection con = ConnectionUtil.getConnection();
        // amqp://guest@117.72.76.16:5672/
        System.out.println(con);
        con.close();
    }
}